#@layout()
#define script()
<script>
    $("input[name='datasource.with_static']").click(function () {

        let isStatic = $("input[name='datasource.with_static']:checked").val();

        if (isStatic == "true") {
            $("#importType").css("display", "");
            $("#importText").css("display", "");
            $("#importUrl").css("display", "none");
            $("#headers").css("display", "none");

            $("#importTextTextarea").prop("name", "datasource.import_text");

            $("#importUrlInput").removeAttr("name")
        } else {
            $("#importType").css("display", "none");
            $("#importText").css("display", "none");
            $("#importUrl").css("display", "");
            $("#headers").css("display", "");

            $('input:radio[name="datasource.import_type"][value="0"]').prop("checked", false);
            $('input:radio[name="datasource.import_type"][value="1"]').prop("checked", false);
            $('input:radio[name="datasource.import_type"][value="2"]').prop("checked", true);

            $("#importUrlInput").prop("name", "datasource.import_text");

            $("#importTextTextarea").removeAttr("name")
        }
    })

</script>
#end

#define content()

<section class="content-header">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-6">

                <div class="row mb-2">
                    <div class="col-sm-12">
                        <h1>
                            #if(datasource.id ??) 编辑数据源 #else 新增数据源 #end
                            <small data-toggle="tooltip" title="" data-placement="right"
                                   data-trigger="hover"><i class="nav-icon far fa-question-circle"></i></small>
                            <small> 首页 / 表单 / 数据源 / #if(datasource.id ??) 编辑 #else 新增 #end </small>
                        </h1>
                    </div>
                </div>
            </div>
        </div>

    </div><!-- /.container-fluid -->
</section>

<section class="content">
    <div class="row">
        <div class="col-12">
            <div class="card card-outline card-primary">
                <form class="autoAjaxSubmit" autocomplete="off"
                      action="#(CPATH)/admin/form/datasource/doSave"
                      data-ok-href="#(CPATH)/admin/form/datasource/list"
                      data-ok-message="数据源保存成功"
                      method="POST">

                    <div class="card-body ">
                        <input type="hidden" id="entryId" name="datasource.id" value="#(datasource.id ??)">


                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">名称</label>
                            <div class="col-sm-6">

                                <input type="text" name="datasource.name" class="form-control"
                                       value="#(datasource.name ??)"
                                       placeholder="请输入字典名称" required>
                            </div>
                        </div>


                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">内容选择</label>
                            <div class="col-sm-6" style="margin-top: 10px">

                                <label for="datasource.with_static1">
                                    <input type="radio" id="datasource.with_static1" name="datasource.with_static"
                                           value=true #if(!datasource || datasource.with_static ??== true) checked #end>静态内容
                                </label>

                                <label for="datasource.with_static2">
                                    <input id="datasource.with_static2" style="margin-left: 10px" type="radio"
                                           name="datasource.with_static" value=false #if(datasource &&
                                           datasource.with_static ??== false ) checked #end>动态内容
                                </label>

                            </div>
                        </div>

                        <div class="form-group row" #if(!datasource.with_static ??) style="display: none" #end
                             id="importType">
                            <div class="col-sm-6" style="margin-top: 10px">
                                <div style="margin-left: 20px;display: none">
                                    <input type="radio" name="datasource.import_type" value="2"
                                           #if(!datasource.with_static ??) checked #end>动态URL
                                </div>

                            </div>
                        </div>

                        <div class="form-group row" id="importText" #if(datasource.with_static ??== false)
                             style="display: none" #else #end>
                            <label class="col-sm-2 col-form-label">说明：</label>
                            <div class="col-sm-6 text-muted" style="padding-top: 7.5px;">
                                静态内容只能在创建完数据源后，手动为该数据源添加内容数据。
                            </div>
                        </div>

                        <div class="form-group row" #if(datasource.with_static ??== true || !datasource)
                             style="display: none" #end id="importUrl">
                            <label class="col-sm-2 col-form-label">动态URL</label>
                            <div class="col-sm-6">

                                <input type="text" id="importUrlInput" class="form-control"
                                       value="#(datasource.import_text ??)" name="datasource.import_text"
                                       placeholder="请输入导入数据的url">
                                <p class="text-muted"> URL 返回的数据 应为 json 格式内容 例如：
                                    <br/>

                                    <code>[
                                        {
                                        "text": "text1",
                                        "value": "value1"
                                        },
                                        {
                                        "text": "text2",
                                        "value": "value2"
                                        }
                                        ]</code>
                                </p>

                            </div>
                        </div>

                        <div class="form-group row" #if(datasource.with_static ??== true || !datasource)
                             style="display: none" #end id="headers">
                            <label class="col-sm-2 col-form-label">headers</label>
                            <div class="col-sm-6">

                                <textarea placeholder="请输入导入数据的headers信息" rows="5" class="form-control"
                                          name="datasource.headers">#(datasource.headers ??)</textarea>

                            </div>
                        </div>

                    </div>
                    <!-- /.card-body -->
                    <div class="card-footer">
                        <div class="offset-sm-2 col-sm-10 submit-block">
                            <div class="card-submit">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </div>
                    <!-- /.card-footer -->
                </form>
            </div>
        </div>
    </div>

</section>

#end
